package bme.andraskindler.treenventory.fragment;

import bme.andraskindler.treenventory.activity.CameraActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

/**
 * 
 * @author andraskindler
 * 
 *         Ez a dialog jelenik meg a {@link CameraActivity}-ben, ha nincs engedélyezve a pozicionálás a telefonon. Az 'igen' gombra kattintva a beállítások megfelelő aloldalára ugrik a rendszer.
 */
public class LocationDialogFragment extends DialogFragment {

	public LocationDialogFragment() {
		super();
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setMessage("A GPS ki van kapcsolva, szeretné engedélyezni?").setCancelable(false).setPositiveButton("Igen", new DialogInterface.OnClickListener() {
			public void onClick(final DialogInterface dialog, final int id) {
				startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
			}
		}).setNegativeButton("Nem", new DialogInterface.OnClickListener() {
			public void onClick(final DialogInterface dialog, final int id) {
				dialog.cancel();
			}
		});
		return builder.create();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo);
		super.onCreate(savedInstanceState);
	}

	public static LocationDialogFragment newInstance() {
		return new LocationDialogFragment();
	}

}
